﻿namespace DafYomiLib
{
    using System.Collections.Generic;

    public enum Page
    {
        A = 0,
        B,
    }

    public class TractateDetails
    {
        private const int c_defaultFirstPageNumber = 2;
        private const Page c_defaultFirstPage = Page.A;

        private static int s_ordinalSequence = 0;

        public TractateDetails(Tractate tractate, int lastPageNumber, Page lastPage)
            : this(tractate, c_defaultFirstPageNumber, c_defaultFirstPage, lastPageNumber, lastPage)
        {
        }

        public TractateDetails(Tractate tractate, int firstPageNumber, Page firstPage, int lastPageNumber, Page lastPage, bool firstPageContainsPreviousTractate = false)
        {
            Tractate = tractate;
            LastPageNumber = lastPageNumber;
            LastPage = lastPage;
            FirstPageNumber = firstPageNumber;
            FirstPage = firstPage;
            FirstPageContainsPreviousTractate = firstPageContainsPreviousTractate;
            OrdinalSequence = ++s_ordinalSequence;
        }

        public Tractate Tractate { get; private set; }

        public string HebrewName { get { return Tractates.ToHebrew(Tractate); }}

        public int NumberOfDoubledPages
        {
            get
            {
                return LastPageNumber - FirstPageNumber + (FirstPageContainsPreviousTractate?0:1);
            }
        }

        public int FirstPageNumber { get; private set; }

        public int LastPageNumber { get; private set; }

        public Page FirstPage { get; private set; }

        public Page LastPage { get; private set; }

        public bool FirstPageContainsPreviousTractate { get; private set; }

        public int OrdinalSequence { get; private set; }
    }

    public enum Tractate
    {
        General = 0,
        Brachot = 1,
        Shabat = 2,
        Eiruvin = 3,
        Psachim = 4,
        Shkalim = 5,
        Yoma = 6,
        Suka = 7,
        Beitza = 8,
        RoshHashana = 9,
        Taaniat = 10,
        Megila = 11,
        MoedKatan = 12,
        Chagiga = 13,
        Yevamot = 14,
        Ktoobot = 15,
        Nedarim = 16,
        Nazir = 17,
        Sota = 18,
        Gitin = 19,
        Kidooshin = 20,
        BabaKama = 21,
        BabaMetziaa = 22,
        BabaBatra = 23,
        Sanhedrin = 24,
        Makot = 25,
        Shvuot = 26,
        AvodaZara = 27,
        Horayot = 28,
        Zvachim = 29,
        Menachot = 30,
        Choolin = 31,
        Bechorot = 32,
        Arachin = 33,
        Tmoora = 34,
        Kritoot = 35,
        Meila = 36,
        Kanim = 37,
        Tamid = 38,
        Midot = 39,
        Nida = 40,
    }

    static class Tractates
    {
        private static Dictionary<Tractate, string> s_tractatesHebrewNames = new Dictionary<Tractate, string>
            {
                {Tractate.General, "כללי"},
                {Tractate.Brachot, "ברכות"},
                {Tractate.Shabat, "שבת"},
                {Tractate.Eiruvin, "עירובין"},
                {Tractate.Psachim, "פסחים"},
                {Tractate.Shkalim, "שקלים"},
                {Tractate.Yoma, "יומא"},
                {Tractate.Suka, "סוכה"},
                {Tractate.Beitza, "ביצה"},
                {Tractate.RoshHashana, "ראש השנה"},
                {Tractate.Taaniat, "תענית"},
                {Tractate.Megila, "מגילה"},
                {Tractate.MoedKatan, "מועד קטן"},
                {Tractate.Chagiga, "חגיגה"},
                {Tractate.Yevamot, "יבמות"},
                {Tractate.Ktoobot, "כתובות"},
                {Tractate.Nedarim, "נדרים"},
                {Tractate.Nazir, "נזיר"},
                {Tractate.Sota, "סוטה"},
                {Tractate.Gitin, "גיטין"},
                {Tractate.Kidooshin, "קידושין"},
                {Tractate.BabaKama, "בבא קמא"},
                {Tractate.BabaMetziaa, "בבא מציעא"},
                {Tractate.BabaBatra, "בבא בתרא"},
                {Tractate.Sanhedrin, "סנהדרין"},
                {Tractate.Makot, "מכות"},
                {Tractate.Shvuot, "שבועות"},
                {Tractate.AvodaZara, "עבודה זרה"},
                {Tractate.Horayot, "הוריות"},
                {Tractate.Zvachim, "זבחים"},
                {Tractate.Menachot, "מנחות"},
                {Tractate.Choolin, "חולין"},
                {Tractate.Bechorot, "בכורות"},
                {Tractate.Arachin, "ערכין"},
                {Tractate.Tmoora, "תמורה"},
                {Tractate.Kritoot, "כריתות"},
                {Tractate.Meila, "מעילה"},
                {Tractate.Kanim, "קנים"},
                {Tractate.Tamid, "תמיד"},
                {Tractate.Midot, "מידות"},
                {Tractate.Nida, "נדה"},
            };

        public const int TractateBase = 282;

        static public string ToHebrew(Tractate tractate)
        {
            return s_tractatesHebrewNames[tractate];
        }
    }
}